<extend file="./resource/view/master"/>
<block name="content">
    <style>
        textarea{
            resize: none;
        }
        #upload li{
            list-style: none;
            float: left;
            position: relative;
        }
        #upload li .delImg{
            position: absolute;
            top: 0;right: 0;
        }
    </style>
    <ol class="breadcrumb" style="background-color: #f9f9f9;padding:8px 0;margin-bottom:10px;">
        <li>
            <a href=""><i class="fa fa-cogs"></i>
                文章管理</a>
        </li>
        <li class="active">
            <a href="">文章编辑</a>
        </li>
    </ol>
    <ul class="nav nav-tabs" role="tablist">
        <li><a href="{{u('index')}}">文章管理</a></li>
        <li class="active"><a href="">文章编辑</a></li>
    </ul>
    <form class="form-horizontal" id="form" onsubmit="return edit(this)" action="" method="post">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">文章管理</h3>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">文章标题</label>
                    <div class="col-sm-9">
                        <input type="text" name="title"  class="form-control" value="{{$oldData['title']}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">文章作者</label>
                    <div class="col-sm-9">
                        <input type="text" name="author"  class="form-control" value="{{$oldData['author']}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">所属分类</label>
                    <div class="col-sm-9">
                        <select class="js-example-basic-single form-control" name="category_cid">
                            <foreach from="$cateData" key="$k" value="$v">
                                <option value="{{$v['cid']}}" <if value="$v['cid']==$oldData['category_cid']">selected</if> >{{$v['_cname']}}</option>
                            </foreach>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">标签</label>
                    <div class="col-sm-9">
                        <foreach from="$tagData" key="$k" value="$v">
                            <label class="checkbox-inline">
                                <!--                                注意：标签name是一个数组-->
                                <input type="checkbox" name="tag[]" value="{{$v['tid']}}" <if value="in_array($v['tid'],$oldTag)">checked</if>     >{{$v['tname']}}
                            </label>
                        </foreach>
                    </div>
                </div>


                <!-- uploadify插件-->
                <script src="./resource/uploadify/jquery.uploadify.min.js"></script>
                <link rel="stylesheet" href="./resource/uploadify/uploadify.css">
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">缩略图</label>
                    <div class="col-sm-9">
                        <div class="input-group">
                            <input type="file" name="file_upload" id="file_upload">
                            <!--                            因为有了id="file_upload"被上面绑定,所以表单不会提交name="file_upload",而是提交隐藏域的upfile-->
                            <script>
                                $(function () {
                                    $("#file_upload").uploadify({
                                        "height"        : 30,
                                        "swf"           : 'resource/uploadify/uploadify.swf',
                                        "uploader"      : "{{u('admin.article.upload')}}",//上传后到哪里处理
                                        "width"         : 120,
                                        'buttonText' : '请选择文件...',
                                        'removeTimeout' : 0.3,//上传进度的时间
                                        'onUploadSuccess':function (file,data,response) {
                                            //alert(data);返回后台路径 attachment/342343.png
                                            str ='<li>';
                                            str += '<img width="60px" src="'+data+'" alt="">';
                                            str +=  '<a href="javascipt:;" class="delImg" path="'+data+'">X</a>';
                                            //图片是让人看得，图片的路径才是实际上传的，所以放在隐藏域里
                                            str += '<input type="hidden" name="thumb"  value="'+data+'">';
                                            str += '</li>';
                                            //#upload里面追加li
                                            $("#upload").append(str);
                                        }
                                    })
                                })
                            </script>
                            <div id="upload"></div>
                        </div>
                        <script>
                            //异步删除，先把后台数据删除，再删页面数据（只删页面，后台数据留在服务器中了，不行）
                            $("#upload").on('click','.delImg',function () {
                                //$(this)是.delImg
                                var path = $(this).attr('path');
                                var _this = $(this);
                                //alert(path)
                                //$.post格式：请求地址，请求参数，成功返回，数据类型，比$.ajax少些很多url dataType data
                                $.post("{{u('delImg')}}",{path:path},function (res) {
                                    //把li里面的东西全删除
                                    _this.parent('li').remove();
                                },'json')
                            })
                        </script>
                        <span class="help-block">建议大小(宽100高100)</span>
                    </div>
                </div>











                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">文章摘要</label>
                    <div class="col-sm-9">
                        <textarea type="text" name="digest"  class="form-control" placeholder="文章摘要">{{$oldData['digest']}}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">关键字</label>
                    <div class="col-sm-9">
                        <textarea type="text" name="keywords"  class="form-control" placeholder="关键字">{{$oldData['keywords']}}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">文章描述</label>
                    <div class="col-sm-9">
                        <textarea type="text" name="des"  class="form-control" placeholder="文章描述">{{$oldData['des']}}</textarea>
                    </div>
                </div>



                <!--百度编辑器引入，这是以前的百度编辑器代码，因为这几个js文件没有，所以报错-->
                <!--                <script type="text/javascript" charset="utf-8" src="./ueditor1_4_3/ueditor.config.js"></script>-->
                <!--                <script type="text/javascript" charset="utf-8" src="./ueditor1_4_3/ueditor.all.min.js"> </script>-->
                <!--                <script type="text/javascript" charset="utf-8" src="./ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>-->
                <!--                <div class="form-group">-->
                <!--                    <label for=""  class="col-sm-2 control-label">文章内容</label>-->
                <!--                    <div class="col-sm-9">-->
                <!--                        <script id="ed1" type="text/plain" style="width:100%;height:300px;" name="content"></script>-->
                <!--                        <script>-->
                <!--                            var ue = UE.getEditor('ed1');-->
                <!--                        </script>-->
                <!--                    </div>-->
                <!--                </div>-->

                <!--                所以要使用框架里的百度编辑器-->
                <div class="form-group">
                    <label for="" class="col-sm-2 control-label">文章内容</label>
                    <div class="col-sm-9">
                        <textarea name="content" id="container" style="height:300px;width:100%;">{{$oldData['content']}}</textarea>
                        <script>
                            util.ueditor('container', {hash:2,data:'hd'}, function (editor) {
                                //这是回调函数 editor是百度编辑器实例
                            });
                        </script>
                    </div>
                </div>

            </div>
        </div>
        <input type="hidden" name="aid" value="{{$_GET['aid']}}">
        <button class="btn btn-primary" type="submit">确定</button>
    </form>
</block>
<!--异步-->
<script>
    function edit(obj) {
        //序列化获取表单数据
        var data=$(obj).serialize();
        //alert(data)   结果csrf=&title=34&author&category_cid=1&
//        之前写成了u('store')结果编辑成了添加
        $.post("{{u('edit')}}",data,function (res) {
            //res:{valid:1,message:'响应信息'}
            if(res.valid){
                util.message(res.message,"{{u('index')}}",'success');
            }else{
                util.message(res.message,'back','error');
            }
        },'json');
        return false;
    }
</script>